package org.yellow.backend.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import org.yellow.backend.pojo.LoginUser;
import org.yellow.backend.pojo.ResponseResult;
import org.yellow.backend.pojo.User;
import org.yellow.backend.service.LoginService;

@RestController
public class LoginController {
    @GetMapping("/user/hello")
//    @PreAuthorize("hasAuthority('patient:test')")
    public ResponseResult hello(){
        return  loginService.logout();
    }
    @Autowired
    private LoginService loginService;

    @CrossOrigin
    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user){
        //登录
        return loginService.login(user);
    }

    @PostMapping("/user/update")
    public ResponseResult alert(@RequestBody User user){
        //登录
        return loginService.update(user);
    }

    @CrossOrigin
    @GetMapping("/user/logout")
    public ResponseResult logout(){
        return  loginService.logout();
    }

    @CrossOrigin
    @PostMapping("/user/register")
    public ResponseResult register(@RequestBody User user){
        return loginService.register(user);
    }

}
